/* << fastinsert report library >> GridOci.h  Nov 1, 2010
 *
 * 	http://code.google.com/p/libfir
 *
 * Copyright (c) 2005 Pavlo Drobov (drobov.pavel@gmail.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */


/*
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 * ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA ALFA
 */



#ifndef GRIDOCI_H_
#define GRIDOCI_H_

#include <oci.h>

#include "IGrid.h"
#include "Text.h"
#include "Debug.h"

namespace dasco
{
namespace report
{

#pragma pack(push)
#pragma pack(1)

//! \struct AOciCell
//! \brief TODO: documented me
struct AOciCell
	:ICell
{
	OCIIOV iov;
	ub2 indname;
	ub4 _oci_typecode;

	virtual ~AOciCell();
	virtual void allocate();

	//ICell iface
	unsigned getLength() const {return iov.bfl;}
	operator const char* () const{ return asText();};
	//end ICell iface
};

//! \struct AOciCell
//! \brief TODO: documented me
template <int>
struct OciCell
	:AOciCell
{
};



//! \struct OciCell
//! \brief TODO: documented OCI_TYPECODE_INTEGER
template<>
struct OciCell<OCI_TYPECODE_INTEGER>
	:AOciCell
{
	OciCell()
		:txt(NULL)
	{
		//DEBUG_MSG("HELLO I AM CONSTRUCTOR: OciCell<OCI_TYPECODE_INTEGER>" );
		cellType = CellInt;
		_oci_typecode = OCI_TYPECODE_INTEGER;
		iov.bfl = sizeof(ub4);
		indname = 0;
	}

	virtual ~OciCell()
	{
		delete txt;
//		DEBUG_MSG("HELLO I AM DESTRUCTOR: OciCell<OCI_TYPECODE_INTEGER>" );
	}
	const char* asText() const
	{
		if(!txt)
			txt = new Text(*(int*)iov.bfp);
		return txt->text;
	}

private:
	mutable Text* txt;
//	Debug& friend operator << (Debug& debug,OciCell<OCI_TYPECODE_INTEGER>* )
};

//! \struct OciCell
//! \brief TODO: documented OCI_TYPECODE_VARCHAR2
template<>
struct OciCell<OCI_TYPECODE_VARCHAR2>
	:AOciCell
{
	OciCell(ub4 len)
    {
		//DEBUG_MSG("HELLO I AM CONSTRUCTOR: OciCell<OCI_TYPECODE_VARCHAR2> ; len: " << len);
		cellType = CellText;
		_oci_typecode = SQLT_CHR;
		iov.bfl = len +1;
		indname = 0;
	}
	const char* asText() const { return (char*) iov.bfp;}
};

#pragma pack(pop)


/*
class GridOci
{
public:
	GridOci();
	virtual ~GridOci();
};
*/

}} //end namespace dasco::report


#endif /* GRIDOCI_H_ */
